<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport"
			content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<script src="../js/mui.js"></script>
		<script type="text/javascript">
			mui.init()
		</script>
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<link href="../css/mui.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">修改密码</h1>
		</header>
		<div class="mui-content">
			<form class="mui-input-group">
				<div class="mui-input-row">
					<label>输入密码</label>
					<input type="text" class="mui-input-clear mm" placeholder="请输入密码">
				</div>
				<div class="mui-input-row">
					<label>确认密码</label>
					<input type="password" class="mui-input-password qrmm" placeholder="请输入密码">
				</div>
				<div class="mui-button-row">
					<button type="button" class="mui-btn mui-btn-primary b_t_n">确认</button>
					<button type="button" class="mui-btn mui-btn-danger b_n">取消</button>
				</div>
			</form>
		</div>
	</body>
	<script>
		let emails = localStorage.getItem('email')

		// 点击确定修改密码
		$('.b_t_n').on('tap', function() {
			if ($('.mm').val() == $('.qrmm').val() && $('.mm').val() !== '') {
				password(emails)
				alert('修改成功')
				window.location.href = '../index.html'
			} else {
				alert('密码未输入或错误')
			}
		})

		// 点击取消返回主页
		$('.b_n').on('tap', function() {
			window.location.href = '../index.html'
		})


		// 修改密码接口
		function password(emails) {
			mui.ajax('http://192.168.0.111:3000/users/update', {
				data: {
					email: emails,
					password: $('.qrmm').val()
				},
				dataType: 'json', //服务器返回json格式数据
				type: 'get', //HTTP请求类型	              
				success: function(res) {
					console.log(res);
				},
				error: function(xhr, type, errorThrown) {
					//异常处理；
					console.log(type);
				}
			});
		}
	</script>
</html>